package com.chexiehui.jc.mvp.car;

import com.chexiehui.jc.Constants;
import com.chexiehui.jc.base.ApiCallback;
import com.chexiehui.jc.base.BaseModel;
import com.chexiehui.jc.base.BasePresenter;
import com.chexiehui.jc.entity.CarInfo;

/**
 * @Description 二手车详情
 * @Auth SongJun
 * @Date 2020/05/21 00:18
 **/
public class CarGarageAssistantDetailsPresenter extends BasePresenter<CarGarageAssistantDetailsCovenant.View, CarGarageAssistantDetailsCovenant.Stores>
        implements CarGarageAssistantDetailsCovenant.Presenter {

    public CarGarageAssistantDetailsPresenter(CarGarageAssistantDetailsCovenant.View view) {
        attachView(view);
    }

    @Override
    public void getDetailsInfo() {
        addSubscription(appStores.getDetailsInfo(mvpView.getCarId()),
                new ApiCallback<BaseModel<CarInfo>>(mvpView) {
                    @Override
                    public void onSuccess(BaseModel<CarInfo> model) {
                        if (model.getResultCode() == 0) {
                            if (model.getData() != null) {
                                mvpView.onGetDetailsInfoSuccess(model);
                            } else {
                                onFailure(Constants.PAGE_DATA_EMPTY, "暂无车辆信息");
                            }
                        } else {
                            onFailure(model.getResultCode(), model.getResultInfo());
                        }
                    }

                    @Override
                    public void onFailure(int code, String msg) {
                        mvpView.onGetDetailsInfoFailure(new BaseModel<>(code, msg));
                    }
                });
    }

}